import {defineStore} from "pinia";
import {computed, ComputedRef, ref} from "vue";
import {currentWorkDataInterface, paramsInterface, scheduleInterface} from "@/views/hospital/interface/interface.ts";
import {getHospitalWorkAPI, getScheduleListAPI} from "@/api/bookingApi.ts";

const useBookingStore = defineStore('bookingStore', () => {
    const bookInfo = ref<any>({})
    const scheduleList = ref<any>([])
    const fetchBookInfo = async (params: paramsInterface) => {
        const {data} = await getHospitalWorkAPI(params)
        bookInfo.value = data
    }
    const fetchScheduleList = async (scheduleParams: scheduleInterface) => {
        const {data} = await getScheduleListAPI(scheduleParams)
        scheduleList.value = data
    }
    const currentWorkData: ComputedRef<currentWorkDataInterface> = computed(() => bookInfo?.value?.bookingScheduleList[0] || {})
    const moringScheduleList = computed(() => scheduleList.value.filter(item => item.workTime === 0))
    const afterScheduleList = computed(() => scheduleList.value.filter(item => item.workTime === 1))
    return {
        bookInfo,
        currentWorkData,
        scheduleList,
        moringScheduleList,
        afterScheduleList,
        fetchBookInfo,
        fetchScheduleList
    }
})


export default useBookingStore
